home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-04-10 | 46.6 KB | 2,378 lines | [TEXT/PJMM] |
- { Written by Brendan Murphy }
- { Version 1.0 }
-
- UNIT CSFDialogs;
-
- INTERFACE { TwilightZone }
-
- USES
- TCL, Disks;
- { Make sure you have included 'Disks.p' in your project }
-
- CONST
- cmdDiskEvent = 552;
- ScrDmpEnb = $2F8; { Global }
-
- { Button stuff }
- kScrollBarWidth = 15;
- kButtonHeight = 17;
- kGetButtonOffset = 264;
- kSaveButtonOffset = 226;
-
- { Resource IDs }
- kRadioButton = 1;
- kCheckButton = 2;
- KPushButton = 3;
-
- { Buttons }
- kCancelButton = 20001;
- kEjectButton = 20002;
- kDriveButton = 20003;
- kOpenButton = 20004;
- kSaveButton = 20005;
-
- { More commands }
- kSelection = 21000;
- kEmptyText = 21001;
- kNonEmptyText = 21002;
-
- { Red Alert Errors }
- kDiskNotFound = -3994;
- kSystemError = -3995;
- kExistingFile = -3996;
- kLockedDisk = -3997;
-
- TYPE
-
- { Shows volume name and icon }
- CSFVolumeBox = OBJECT(CPane)
- PROCEDURE Draw (VAR Area: Rect);
- Override;
- PROCEDURE DoClick (hitPt: Point; modifierKeys: integer; when: longint);
- Override;
- END;
-
-
- { Text edit box for save dialog }
- CSFEditText = OBJECT(CEditText)
- fEmpty: Boolean; { Anybody Home? }
-
- PROCEDURE IEditText (anEnclosure: CView; aSupervisor: CBureaucrat; aWidth, aHeight, aHEncl, aVEncl: integer; aHSizing, aVSizing: SizingOption; aLineWidth: integer);
- Override;
- PROCEDURE DoKeyDown (theChar: char; keyCode: Byte; macEvent: EventRecord);
- Override;
- PROCEDURE SetText;
- FUNCTION IsEmpty: Boolean;
- PROCEDURE Dawdle (VAR maxSleep: Longint);
- Override;
- PROCEDURE SelectText;
- FUNCTION GetStr255: Str255;
- END;
-
-
- { Main window class }
- CSFWindow = OBJECT(CWindow)
- fInitTime: Boolean;
-
- { Button references }
- fEject, fDrive, fCancel: CButton;
-
- fVolumeBox: CSFVolumeBox;
-
- { Holds the file listings }
- fFileList: ListHandle;
- fViewRect: Rect;
-
- { Holds the path to the directory }
- fPathList: ListHandle;
- fPathRect: Rect;
- fMenuWidth: Integer;
- fMenuHeight: Integer;
-
- fDriveIndex: Integer;
- fDrive1, fDrive2: Integer;
-
- { Internal directory information }
- fCurrentWD: Integer; { Holds current working directory }
- fGood: Boolean;
- fName: Str255;
- fVName: Str255;
-
- PROCEDURE ICSFWindow (TheDirector: CDirector);
- PROCEDURE MoreInitializations;
- PROCEDURE SetfViewRect;
- PROCEDURE DoKeyDown (theChar: char; keyCode: Byte; macEvent: EventRecord);
- Override;
- PROCEDURE DoCommand (TheCommand: Longint);
- Override;
- PROCEDURE Update;
- Override;
- PROCEDURE MoreUpdates;
- PROCEDURE Free;
- Override;
- PROCEDURE DoClick (hitPt: Point; modifierKeys: integer; when: longint);
- Override;
- PROCEDURE Activate;
- Override;
- PROCEDURE Deactivate;
- Override;
- PROCEDURE Close;
- Override;
-
- FUNCTION CountDrives: Integer;
- FUNCTION GetNextVol: Integer;
- FUNCTION CheckDrives: Boolean;
-
- PROCEDURE DoEject;
- PROCEDURE DoDrive;
- PROCEDURE DoCancel;
- PROCEDURE DoStatus;
-
- FUNCTION FileFilter (ParamBlock: CInfoPBPtr): Boolean;
- FUNCTION ActiveFilter (ParamBlock: CInfoPBPtr): Boolean;
- PROCEDURE FillDialog (VRefNum: Integer);
-
- PROCEDURE SetPathRect;
- PROCEDURE FindPath (VRefNum: Integer);
- FUNCTION FindSelection: Str255;
-
- PROCEDURE DoSelection;
- PROCEDURE FileSelected (TheReply: SFReply);
-
- FUNCTION RedAlert (AlertID: Integer): Integer;
- END;
-
-
- { Subclasses of main window }
- { You will want to override these subclasses }
-
- CSFGetWindow = OBJECT(CSFWindow)
- fOpen: CButton;
-
- PROCEDURE MoreInitializations;
- Override;
- PROCEDURE DoKeyDown (theChar: char; keyCode: Byte; macEvent: EventRecord);
- Override;
- PROCEDURE SetfViewRect;
- Override;
- PROCEDURE MoreUpdates;
- Override;
- PROCEDURE DoStatus;
- Override;
- PROCEDURE DoClick (hitPt: Point; modifierKeys: integer; when: longint);
- Override;
- PROCEDURE DoCommand (TheCommand: Longint);
- Override;
- PROCEDURE Free;
- Override;
- PROCEDURE DoOpen;
- END;
-
-
- CSFSaveWindow = OBJECT(CSFWindow)
- fSave: CButton;
- fFileName: CSFEditText;
- fPromptString: Str255;
-
- PROCEDURE MoreInitializations;
- Override;
- PROCEDURE SetfViewRect;
- Override;
- FUNCTION ActiveFilter (ParamBlock: CInfoPBPtr): Boolean;
- Override;
- PROCEDURE Activate;
- Override;
- PROCEDURE DoCommand (TheCommand: Longint);
- Override;
- PROCEDURE MoreUpdates;
- Override;
- PROCEDURE Free;
- Override;
- FUNCTION FileExists (vRefNum: Integer; TheName: Str255): Boolean;
- PROCEDURE DoSave;
- END;
-
-
- { Also make sure to create subclasses of these directors }
-
- CSFDialog = OBJECT(CDirector)
- PROCEDURE ICSFDialog;
- END;
-
-
- CSFGetDialog = OBJECT(CSFDialog)
- PROCEDURE ICSFDialog;
- Override;
- END;
-
-
- CSFSaveDialog = OBJECT(CSFDialog)
- PROCEDURE ICSFDialog;
- Override;
- END;
-
-
- { You don't have to do anything with the switchboard since }
- { it is installed by the CSFApplication }
-
- CSFSwitchboard = OBJECT(CSwitchBoard)
- PROCEDURE DoDiskEvent (macEvent: EventRecord);
- Override;
- END;
-
-
- { Make sure this class is installed in your application! }
-
- CSFApplication = OBJECT(CApplication)
- PROCEDURE ICSFApplication (extraMasters: integer; aRainyDayFund, aCreditLimit: Size);
- END;
-
-
- IMPLEMENTATION
-
- VAR
- { This list handle is critcal to the ClickLoop routine. }
- { It holds the current path menu list. }
- ThePathList: ListHandle;
- ThePathCell: Cell;
-
-
- FUNCTION IsDirectory (ParamBlock: CInfoPBPtr): Boolean;
- { Is this a directory? }
-
- BEGIN
-
- IsDirectory := BitTst(@ParamBlock^.ioFLAttrib, 3);
-
- END;
-
-
- PROCEDURE DropShadow (TheRect: Rect);
- { Draw a shadow around the box }
-
- BEGIN
-
- Moveto(TheRect.Left + 1, TheRect.Bottom);
- Lineto(TheRect.Right, TheRect.Bottom);
- Lineto(TheRect.Right, TheRect.Top + 1);
-
- END;
-
-
- PROCEDURE FKeyEnable (OnOff: Boolean);
- { Turn off function keys }
- { Can't normaly intercept all disk events }
- { because they are masked out by the system }
- { before they are put in the event queue. }
-
- VAR
- P: Ptr;
-
- BEGIN
-
- { Enable Shift-Command-Keys }
- P := Ptr(ScrDmpEnb);
- IF OnOff THEN
- P^ := $FF
- ELSE
- P^ := $00
-
- END;
-
-
- FUNCTION GetCellContents (TheCell: Cell; TheList: Listhandle): Str255;
- { Transform the cell data into a Pascal string. }
-
- VAR
- TempStr: Str255;
- DataLength: Integer;
-
- BEGIN
-
- TempStr := '';
- DataLength := 255;
- LGetCell(Ptr(Longint(@TempStr) + 1), DataLength, TheCell, TheList);
- BlockMove(Ptr(Longint(@DataLength) + 1), @TempStr, 1);
- GetCellContents := TempStr;
-
- END;
-
-
- FUNCTION ClickLoop: Boolean;
- { Gives those pull down menus that special flavor }
- { Since we use a custom LDEF, we must roll our own here }
- { and damn the torpedos!!! }
-
- VAR
- ThePoint, TheCell, TheNewCell: Point;
- Contents: Str255;
- OffSet: Integer;
-
- BEGIN
-
- OffSet := 0;
- WHILE StillDown DO
- BEGIN
- GetMouse(ThePoint);
- IF NOT PtInRect(ThePoint, ThePathList^^.rView) THEN
- BEGIN
- { We are not in the menu }
- SetPt(TheCell, 0, 0);
-
- { Cell Selected? }
- IF LGetSelect(True, TheCell, ThePathList) THEN
- BEGIN
- LSetSelect(False, TheCell, ThePathList);
- SetPt(ThePathCell, 0, 0);
- END;
-
- { Should we scroll? }
- IF (ThePoint.h > ThePathList^^.rView.Left) AND (ThePoint.h < ThePathList^^.rView.Right) THEN
- BEGIN
- { Up or down? }
- IF (ThePoint.v >= ThePathList^^.rView.Top) THEN
- BEGIN
- SetPt(TheCell, 0, ((ThePathList^^.rView.Bottom - ThePathList^^.rView.Top + 1) DIV ThePathList^^.CellSize.v) + Offset);
- IF TheCell.v < ThePathList^^.dataBounds.Bottom THEN
- BEGIN
- LScroll(0, 1, ThePathList);
- IF Offset < ThePathList^^.dataBounds.Bottom THEN
- Offset := Offset + 1;
- END;
- END
- ELSE
- BEGIN
- SetPt(TheCell, 0, ((ThePathList^^.rView.Top - 1) DIV ThePathList^^.CellSize.v) + Offset);
- IF TheCell.v > 0 THEN
- BEGIN
- LScroll(0, -1, ThePathList);
- IF Offset > 0 THEN
- Offset := Offset - 1;
- END;
- END;
- END;
- END
- ELSE
- BEGIN
- { We are in the menu }
- SetPt(TheCell, 0, 0);
- IF LGetSelect(True, TheCell, ThePathList) THEN
- BEGIN
- SetPt(TheNewCell, 0, ((ThePoint.v - ThePathList^^.rView.Top) DIV ThePathList^^.CellSize.v) + Offset);
- { Do we need to select a cell? }
- IF TheNewCell.v <> TheCell.v THEN
- BEGIN
- LSetSelect(False, TheCell, ThePathList);
- LSetSelect(True, TheNewCell, ThePathList);
- ThePathCell := TheNewCell;
- END;
- END
- ELSE
- BEGIN
- { Nothing turned on so turn something on }
- SetPt(TheCell, 0, ((ThePoint.v - ThePathList^^.rView.Top) DIV ThePathList^^.CellSize.v) + Offset);
- LSetSelect(True, TheCell, ThePathList);
- ThePathCell := TheCell;
- END;
- END;
- END;
-
- { Scroll menu back }
- IF Offset > 0 THEN
- BEGIN
- LDoDraw(False, ThePathList);
- LScroll(0, -Offset, ThePathList);
- LDoDraw(True, ThePathList);
- END;
-
- ClickLoop := False;
-
- END;
-
-
- FUNCTION ChangeDirectory (VRefNum: Integer; TheFolder: Str255): Integer;
- { Change the working directory }
-
- VAR
- ParamBlock: CInfoPBPtr;
- WDBlock: WDPBPtr;
- Err: OSErr;
-
- BEGIN
-
- ParamBlock := CInfoPBPtr(NewPtr(SizeOf(CInfoPBRec)));
- WDBlock := WDPBPtr(NewPtr(SizeOf(WDPBRec)));
-
- { Find out where we are }
- Err := NoErr;
- WITH WDBlock^ DO
- BEGIN
- ioCompletion := NIL;
- ioNamePtr := NIL;
- ioVRefNum := VRefNum;
- ioWDIndex := 0;
- ioWDProcID := 0;
- END;
- Err := PBGetWDInfo(WDBlock, False);
-
- { Open directory named TheFolder. }
- { You would think Apple would provide }
- { more higher level routines to do this }
- { kind of work. }
- ParamBlock^.ioDrParID := WDBlock^.ioWDDirID;
- WITH ParamBlock^ DO
- BEGIN
- ioCompletion := NIL;
- ioNamePtr := @TheFolder;
- ioVRefNum := VRefNum;
- ioDrDirID := 0;
- ioDirID := 0;
- ioFVersNum := 0;
- ioFDirIndex := 0;
- END;
- Err := PBGetCatInfo(ParamBlock, False);
-
- { Open working directory }
- WITH WDBlock^ DO
- BEGIN
- ioCompletion := NIL;
- ioNamePtr := NIL;
- ioVRefNum := VRefNum;
- ioWDDirID := ParamBlock^.ioDrDirID;
- ioWDProcID := 0;
- END;
- Err := PBOpenWD(WDBlock, False);
-
- IF Err <> NoErr THEN
- ChangeDirectory := 0
- ELSE
- ChangeDirectory := WDBlock^.ioVRefNum;
-
- DisposPtr(Ptr(ParamBlock));
-
- END;
-
-
- FUNCTION FindParent (VRefNum: Integer; Levels: Integer): Integer;
- { From a given working directory, find working directory number for }
- { that directory. }
-
- VAR
- ParamBlock: CInfoPBPtr;
- WDBlock: WDPBPtr;
- Err: OSErr;
- i: Integer;
- TheName: Str255;
-
- BEGIN
-
- ParamBlock := CInfoPBPtr(NewPtr(SizeOf(CInfoPBRec)));
- WDBlock := WDPBPtr(NewPtr(SizeOf(WDPBRec)));
-
- Err := NoErr;
- WITH WDBlock^ DO
- BEGIN
- ioCompletion := NIL;
- ioNamePtr := NIL;
- ioVRefNum := VRefNum;
- ioWDIndex := 0;
- ioWDProcID := 0;
- END;
- Err := PBGetWDInfo(WDBlock, False);
-
- { Find directory ID }
- ParamBlock^.ioDrParID := WDBlock^.ioWDDirID;
- i := 1;
- WHILE (Err = NoErr) AND (i <= (Levels + 1)) DO
- BEGIN
- WITH ParamBlock^ DO
- BEGIN
- ioCompletion := NIL;
- ioNamePtr := NIL;
- ioVRefNum := VRefNum;
- ioDrDirID := 0;
- ioDirID := ioDrParID; { We want the parent directory name }
- ioFVersNum := 0;
- ioFDirIndex := -1; { Causes it to give information on ioDrDirID }
- END;
- Err := PBGetCatInfo(ParamBlock, False);
- i := i + 1;
- END;
-
- { Open working directory }
- WITH WDBlock^ DO
- BEGIN
- ioCompletion := NIL;
- ioNamePtr := NIL;
- ioVRefNum := VRefNum;
- ioWDDirID := ParamBlock^.ioDrDirID;
- ioWDProcID := 0;
- END;
- Err := PBOpenWD(WDBlock, False);
-
- IF Err <> NoErr THEN
- FindParent := 0
- ELSE
- FindParent := WDBlock^.ioVRefNum;
-
- DisposPtr(Ptr(ParamBlock));
-
- END;
-
-
- FUNCTION GetVRefNum (WorkingDir: Integer): Integer;
- { Take a working directory and convert it to a volume number }
-
- VAR
- Ignore: Longint;
- VRefNum: Integer;
- Err: OSErr;
-
- BEGIN
-
- { GetWDInfo is a high level equivalent of the PB routine }
- { but not documented in IM}
- Err := GetWDInfo(WorkingDir, VRefNum, Ignore, Ignore);
- GetVRefNum := VRefNum;
-
- END;
-
-
- FUNCTION GetCurWDRefNum: Integer;
- { Get the current system working directory }
-
- CONST
- CurDirStore = $398;
-
- VAR
- Pb: WDPBRec;
- DirID: Longint;
- Index: Integer;
- Err: OSErr;
-
- BEGIN
-
- BlockMove(Ptr(CurDirStore), @DirID, 4);
- Index := 1;
- REPEAT
- WITH Pb DO
- BEGIN
- ioCompletion := NIL;
- ioNamePtr := NIL;
- ioVRefNum := 0;
- ioWDIndex := Index;
- ioWDPROCID := 0;
- ioWDVRefNum := 0;
- END;
- Err := PBGetWDInfo(@Pb, True);
- Index := Index + 1;
- UNTIL (Err <> NoErr) OR (DirID = PB.ioWDDirID);
-
- IF Err = NoErr THEN
- GetCurWDRefNum := Pb.ioVRefNum
- ELSE
- GetCurWDRefNum := 0;
-
- END;
-
-
- PROCEDURE DrawFloppyDisk (Left, Top: Integer);
- { Draw floppy disk icon }
-
- BEGIN
-
- Moveto(Left + 5, Top + 2);
- Lineto(Left + 14, Top + 2);
- Lineto(Left + 16, Top + 4);
- Lineto(Left + 16, Top + 13);
- Lineto(Left + 5, Top + 13);
-
- Moveto(Left + 4, Top + 12);
- Lineto(Left + 4, Top + 3);
-
- Moveto(Left + 13, Top + 3);
- Lineto(Left + 13, Top + 5);
-
- Moveto(Left + 12, Top + 6);
- Lineto(Left + 8, Top + 6);
-
- Moveto(Left + 7, Top + 5);
- Lineto(Left + 7, Top + 3);
-
- Moveto(Left + 11, Top + 3);
- Lineto(Left + 11, Top + 4);
-
-
- Moveto(Left + 7, Top + 12);
- Lineto(Left + 7, Top + 10);
-
- Moveto(Left + 8, Top + 9);
- Lineto(Left + 12, Top + 9);
-
- Moveto(Left + 13, Top + 10);
- Lineto(Left + 13, Top + 12);
-
- END;
-
-
- PROCEDURE DrawHardDrive (Left, Top: Integer);
- { Draw hard disk icon }
-
- BEGIN
-
- Moveto(Left + 3, Top + 6);
- Lineto(Left + 3, Top + 9);
-
- Moveto(Left + 4, Top + 10);
- Lineto(Left + 18, Top + 10);
-
- Moveto(Left + 19, Top + 9);
- Lineto(Left + 19, Top + 6);
-
- Moveto(Left + 18, Top + 5);
- Lineto(Left + 4, Top + 5);
-
- Moveto(Left + 5, Top + 8);
- Lineto(Left + 5, Top + 8);
-
- END;
-
-
- PROCEDURE TrimVolumeName (Area: Rect; Offset: Integer; VAR TheVolume: Str255);
- { the volume name down to size and add a '...' }
-
- VAR
- TheLength: Integer;
- TrimmedVolume: Str255;
-
- BEGIN
-
- TheLength := (Area.Right - Area.Left) - Offset;
- IF Thelength >= StringWidth(TheVolume) THEN
- Exit(TrimVolumeName);
- TrimmedVolume := Concat(Omit(TheVolume, Length(TheVolume), 1), CHR($C9));
- WHILE StringWidth(TrimmedVolume) >= TheLength DO
- BEGIN
- TrimmedVolume := Concat(Omit(TrimmedVolume, Length(TrimmedVolume) - 1, 2), CHR($C9));
- END;
- TheVolume := TrimmedVolume;
-
- END;
-
-
- PROCEDURE CSFVolumeBox.Draw (VAR Area: Rect);
- Override;
- { Draw the icon and then the volume name }
-
- VAR
- TheVolume: Str255;
- VRefNum: Integer;
- Err: OSErr;
-
- BEGIN
-
- EraseRect(Area);
- Err := GetVol(@TheVolume, VRefNum);
- IF CSFWindow(ItsEnclosure).CheckDrives THEN
- BEGIN
- Err := GetVol(@TheVolume, VRefNum);
- { Check floppy drives }
- IF (CSFWindow(ItsEnclosure).fDrive1 = GetVRefNum(VRefNum)) OR (CSFWindow(ItsEnclosure).fDrive2 = GetVRefNum(VRefNum)) THEN
- DrawFloppyDisk(0, 0)
- ELSE
- DrawHardDrive(0, 0);
- END
- ELSE
- DrawHardDrive(0, 0);
- TrimVolumeName(Frame, 23, TheVolume);
- Moveto(23, 12);
- DrawString(TheVolume);
-
- END;
-
-
- PROCEDURE CSFVolumeBox.DoClick (hitPt: Point; modifierKeys: integer; when: longint);
- Override;
- { Change directory if clicked in }
-
- VAR
- TheWindow: CSFWindow;
- Temp: Integer;
-
- BEGIN
-
- { Step up one directory level }
- TheWindow := CSFWindow(ItsEnclosure);
- Temp := FindParent(TheWindow.fCurrentWD, 1);
- IF Temp <> 0 THEN
- BEGIN
- TheWindow.fCurrentWD := Temp;
- TheWindow.FillDialog(TheWindow.fCurrentWD);
- TheWindow.FindPath(TheWindow.fCurrentWD);
- CSFWindow(ItsEnclosure).DoStatus;
- END;
-
- INHERITED DoClick(hitPt, modifierKeys, when);
-
- END;
-
-
- PROCEDURE CSFEditText.IEditText (anEnclosure: CView; aSupervisor: CBureaucrat; aWidth, aHeight, aHEncl, aVEncl: integer; aHSizing, aVSizing: SizingOption; aLineWidth: integer);
- Override;
- { Initialize the text edit box }
-
- BEGIN
-
- INHERITED IEditText(anEnclosure, aSupervisor, aWidth, aHeight, aHEncl, aVEncl, aHSizing, aVSizing, aLineWidth);
-
- { Override settext to insert different text }
- SetText;
-
- END;
-
-
- PROCEDURE CSFEditText.DoKeyDown (theChar: char; keyCode: Byte; macEvent: EventRecord);
- Override;
- { We have to intercept special keys to process them as clicks instead }
-
- BEGIN
-
- CASE keyCode OF
- $24, $34: { return or enter }
- DoCommand(kSaveButton);
- $30: { tab }
- DoCommand(kDriveButton);
- OTHERWISE
- INHERITED DoKeyDown(theChar, keyCode, macEvent);
- END;
-
- { Did we delete everything? }
- IF IsEmpty THEN
- BEGIN
- IF NOT fEmpty THEN
- BEGIN
- fEmpty := True;
- DoCommand(kEmptyText);
- END;
- END
- ELSE
- BEGIN
- IF fEmpty THEN
- BEGIN
- fEmpty := False;
- DoCommand(kNonEmptyText);
- END;
- END;
-
- END;
-
-
- FUNCTION CSFEditText.IsEmpty: Boolean;
- { Is the party over? }
-
- VAR
- DataLength: Longint;
-
- BEGIN
-
- DataLength := macTE^^.teLength;
- IF DataLength = 0 THEN
- IsEmpty := True
- ELSE
- IsEmpty := False;
-
- END;
-
-
- PROCEDURE CSFEditText.SetText;
- { Set the initial text in the edit box }
-
- BEGIN
-
- fEmpty := False;
- SetTextString('Untitled');
- DoCommand(kNonEmptyText);
-
- END;
-
-
- PROCEDURE CSFEditText.Dawdle (VAR maxSleep: Longint);
- Override;
- { Is the edit box empty for any other reason, then notify the dialog }
-
- BEGIN
-
- INHERITED Dawdle(maxSleep);
-
- IF IsEmpty THEN
- BEGIN
- IF NOT fEmpty THEN
- BEGIN
- fEmpty := True;
- DoCommand(kEmptyText);
- END;
- END
- ELSE
- BEGIN
- IF fEmpty THEN
- BEGIN
- fEmpty := False;
- DoCommand(kNonEmptyText);
- END;
- END;
-
- END;
-
-
- PROCEDURE CSFEditText.SelectText;
- { Highlite everything }
-
- BEGIN
-
- TESetSelect(0, Maxint, macTe);
-
- END;
-
-
- FUNCTION CSFEditText.GetStr255: Str255;
- { Return a Pascal string of the first 255 characters }
-
- VAR
- Temp: Str255;
- DataLength: Longint;
- TheCharsHandle: CharsHandle;
-
- BEGIN
-
- Temp := '';
-
- DataLength := macTE^^.teLength;
- IF DataLength > 0 THEN
- BEGIN
- IF DataLength > 255 THEN
- DataLength := 255;
- BlockMove(Ptr(Longint(@DataLength) + 3), @Temp, 1);
-
- TheCharsHandle := GetTextHandle;
- HLock(Handle(TheCharsHandle));
- BlockMove(Ptr(TheCharsHandle^), Ptr(Longint(@Temp) + 1), DataLength);
- HUnLock(Handle(TheCharsHandle));
- END;
-
- GetStr255 := Temp;
-
- END;
-
-
- PROCEDURE CSFWindow.ICSFWindow (TheDirector: CDirector);
- { Initialize the window. Do not override. }
-
- VAR
- TheSize, ViewRect, DataBounds, TheRect: Rect;
- CellSize: Point;
- Err: OSErr;
- TheText, TheName: Str255;
- TheLength, h, v, TheWidth, TheCenter, Ignore: Integer;
-
- BEGIN
-
- { Init the window }
- IWindow(9999, False, gDeskTop, TheDirector);
- Prepare;
- TextFont(SystemFont);
- Move(100, 100);
- SetTitle('Open');
-
- SetRect(TheSize, 0, 0, 70, kButtonHeight);
-
- { Create some buttons }
- New(fEject);
- fEject.IButton(KPushButton, Self, Self);
- fEject.SetClickCmd(kEjectButton);
- fEject.ChangeSize(TheSize, False);
- fEject.SetTitle('Eject');
- IF NOT CheckDrives THEN
- fEject.Deactivate;
- fEject.Show;
-
- New(fDrive);
- fDrive.IButton(KPushButton, Self, Self);
- fDrive.SetClickCmd(kDriveButton);
- fDrive.ChangeSize(TheSize, False);
- fDrive.SetTitle('Drive');
- IF CountDrives = 1 THEN
- fDrive.Deactivate;
- fDrive.Show;
-
- New(fCancel);
- fCancel.IButton(KPushButton, Self, Self);
- fCancel.SetClickCmd(kCancelButton);
- fCancel.ChangeSize(TheSize, False);
- fCancel.SetTitle('Cancel');
- fCancel.Show;
-
- { Create the main file box }
- SetfViewRect;
- SetRect(DataBounds, 0, 0, 1, 0);
- SetPt(CellSize, 1000, 16);
- ClipRect(GetMacPort^.PortRect);
- fFileList := LNew(fViewRect, DataBounds, CellSize, 13000, GetMacPort, True, False, False, True);
- fFileList^^.selFlags := lOnlyOne;
- SetRect(fViewRect, fViewRect.Left, fViewRect.Top, fViewRect.Right + kScrollBarWidth, fViewRect.Bottom);
- InsetRect(fViewRect, -1, -1);
- FrameRect(fViewRect);
- fCurrentWD := GetCurWDRefNum;
-
- { Fill the pull down menu }
- Err := GetVol(@TheName, Ignore);
- TheWidth := StringWidth(TheName) + 28;
- TheCenter := (fViewRect.Right - fViewRect.Left + 16) DIV 2;
- SetRect(fPathRect, TheCenter - (TheWidth DIV 2), fViewRect.Top - 23, TheCenter + (TheWidth DIV 2), fViewRect.Top - 7);
- SetRect(DataBounds, 0, 0, 1, 0);
- SetPt(CellSize, 1000, 16);
- ClipRect(GetMacPort^.PortRect);
- fPathList := LNew(fPathRect, DataBounds, CellSize, 13000, GetMacPort, True, False, False, False);
- fPathList^^.LClikLoop := @ClickLoop;
- ThePathList := fPathList;
- FindPath(fCurrentWD);
- FrameRect(fPathRect);
- DropShadow(fPathRect);
-
- { Here is where your initializations occur }
- MoreInitializations;
-
- New(fVolumeBox);
- fVolumeBox.IPane(Self, Self, (MacPort^.PortRect.Right - 3) - (fViewRect.Right + 3), 16, fViewRect.Right + 3, fViewRect.Top, sizFIXEDLEFT, sizFIXEDTOP);
- fVolumeBox.SetWantsClicks(True);
- fVolumeBox.Show;
-
- fDriveIndex := 0;
-
- fGood := False;
- fName := '';
- fVName := '';
-
- { Show the window }
- Select;
-
- fInitTime := True;
- END;
-
-
- PROCEDURE CSFWindow.MoreInitializations;
- { Override me! }
-
- BEGIN
-
- { Does nothing }
-
- END;
-
-
- PROCEDURE CSFWindow.SetfViewRect;
- { Set the file box rect }
-
- BEGIN
-
- SetRect(fViewRect, 10, 30, 170, 158);
-
- END;
-
-
- PROCEDURE CSFWindow.DoKeyDown (theChar: char; keyCode: Byte; macEvent: EventRecord);
- Override;
- { Intercept the tab key }
-
- BEGIN
-
- CASE keyCode OF
- $30: { tab }
- DoCommand(kDriveButton);
- OTHERWISE
- INHERITED DoKeyDown(theChar, keyCode, macEvent);
- END;
-
- END;
-
-
- PROCEDURE CSFWindow.DoCommand (TheCommand: Longint);
- Override;
- { Handle basic commands }
-
- BEGIN
-
- CASE (TheCommand) OF
- kCancelButton:
- DoCancel;
- kEjectButton:
- DoEject;
- kDriveButton:
- DoDrive;
- cmdDiskEvent:
- DoStatus;
- OTHERWISE
- INHERITED DoCommand(TheCommand);
- END;
-
- END;
-
-
- PROCEDURE CSFWindow.Update;
- Override;
-
- VAR
- savePort: GrafPtr; { The current port }
- updateRect: Rect; { Bounding box of update region }
-
- BEGIN
-
- GetPort(savePort); { Save the original port }
- Prepare;
-
- BeginUpdate(macPort); { Start the update process }
- { This restricts the visible area }
- { to just the update region, }
- { meaning that no drawing will }
- { occur outside this region }
-
- ClipRect(macPort^.portRect); { Clip to the entire window }
-
- { Your updates occur here }
- MoreUpdates;
-
- IF itsSubviews <> NIL THEN
- BEGIN { Draw all subviews }
-
- updateRect := macPort^.visRgn^^.rgnBBox;
- itsSubviews.DoForEach1(Pane_Draw, @updateRect);
- END;
-
- EndUpdate(macPort); { End the update process }
- SetPort(savePort); { Restore the original port }
-
- END;
-
-
- PROCEDURE CSFWindow.MoreUpdates;
- { Override to do your updates }
-
- VAR
- TheRect: Rect;
-
- BEGIN
-
- { update the file box }
- LUpdate(macPort^.VisRgn, fFileList);
- FrameRect(fViewRect);
-
- { update the pull down menu }
- LUpdate(MacPort^.VisRgn, fPathList);
- FrameRect(fPathRect);
- DropShadow(fPathRect);
-
- END;
-
-
- PROCEDURE CSFWindow.Free;
- Override;
- { Dispose of the buttons and stuff }
-
- BEGIN
-
- fEject.Free;
- fDrive.Free;
- fCancel.Free;
- LDispose(fFileList);
- LDispose(fPathList);
- INHERITED Free;
-
- END;
-
-
- PROCEDURE CSFWindow.Activate;
- Override;
- { Set up globals and disable function keys }
-
- VAR
- TheCell: Cell;
-
- BEGIN
-
- INHERITED Activate;
-
- FKeyEnable(False);
- gGopher := Self;
- ThePathList := fPathList;
- FillDialog(fCurrentWD);
-
- { if theis a new window then select }
- IF fInitTime THEN
- BEGIN
- SetPt(TheCell, 0, 0);
- LSetSelect(True, TheCell, fFileList);
- fInitTime := False
- END;
-
- DoStatus;
-
- END;
-
-
- PROCEDURE CSFWindow.Deactivate;
- Override;
- { Clean up after ourselves }
-
- BEGIN
-
- FKeyEnable(True);
- INHERITED Deactivate;
-
- END;
-
-
- PROCEDURE CSFWindow.Close;
- Override;
- { The party is over }
-
- BEGIN
-
- FKeyEnable(True);
- INHERITED Close;
-
- END;
-
-
- FUNCTION CSFWindow.CountDrives: Integer;
- { Count the number of mounted volumes }
-
- VAR
- Index, Count: Integer;
- Err: OSErr;
- PB: HParamBlockRec;
-
- BEGIN
-
- IF CheckDrives THEN
- ;
- Index := 0;
- Count := 0;
- Err := NoErr;
- WHILE Err <> nsvErr DO
- BEGIN
- Index := Index + 1;
- WITH PB DO
- BEGIN
- ioCompletion := NIL;
- ioNamePtr := NIL;
- ioVolIndex := Index;
- END;
- Err := PBHGetVInfo(@PB, False);
- IF (PB.ioVDrvInfo = 0) AND NOT (Err = nsvErr) THEN
- BEGIN
- Err := NoErr;
- Cycle;
- END;
- IF Err <> nsvErr THEN
- Count := Count + 1;
- END;
- CountDrives := Count;
-
- END;
-
-
- FUNCTION CSFWindow.GetNextVol: Integer;
- { Find the next mounted volume }
-
- VAR
- Index: Integer;
- Err: OSErr;
- PB: HParamBlockRec;
-
- BEGIN
-
- IF CheckDrives THEN
- ;
- Index := fDriveIndex;
- Err := paramErr;
- WHILE Err <> NoErr DO
- BEGIN
- Index := Index + 1;
- WITH PB DO
- BEGIN
- ioCompletion := NIL;
- ioNamePtr := NIL;
- ioVolIndex := Index;
- END;
- Err := PBHGetVInfo(@PB, False);
- IF (PB.ioVDrvInfo = 0) AND NOT (Err = nsvErr) THEN
- BEGIN
- Err := nsvErr;
- Cycle;
- END;
- IF Err = nsvErr THEN
- Index := 0;
- END;
- fDriveIndex := Index;
- GetNextVol := PB.ioVRefNum;
-
- END;
-
-
- FUNCTION CSFWindow.CheckDrives: Boolean;
- { Check the status of the floppy disk drives }
-
- VAR
- FreeBytes: Longint;
- Err, Ignore: OSErr;
- Index: Integer;
- Status: DrvSts;
-
- BEGIN
-
- CheckDrives := False;
-
- fDrive1 := 0;
- fDrive2 := 0;
- Err := DriveStatus(1, Status);
- IF (Status.Installed = 1) AND (Status.DiskInPlace <> 0) THEN
- Ignore := GetVInfo(1, NIL, fDrive1, FreeBytes);
-
- Err := DriveStatus(2, Status);
- IF (Status.Installed = 1) AND (Status.DiskInPlace <> 0) THEN
- Ignore := GetVInfo(2, NIL, fDrive2, FreeBytes);
-
- IF (fDrive1 <> 0) OR (fDrive2 <> 0) THEN
- CheckDrives := True;
-
- END;
-
-
- PROCEDURE CSFWindow.DoEject;
- { Eject a floppy disk }
-
- VAR
- WorkingDir: Integer;
- b: boolean;
-
- BEGIN
-
-
- IF fDriveIndex <> 1 THEN
- BEGIN
- b := gError.CheckOSError(Eject(NIL, fCurrentWD));
- fCurrentWD := GetNextVol;
- FillDialog(fCurrentWD);
- FindPath(fCurrentWD);
- DoStatus;
- END;
-
- END;
-
-
- PROCEDURE CSFWindow.DoDrive;
- { Change drives }
-
- BEGIN
-
- IF fDrive.IsActive THEN
- BEGIN
- fCurrentWD := GetNextVol;
- FillDialog(fCurrentWD);
- FindPath(fCurrentWD);
- DoStatus;
- END;
-
- END;
-
-
- PROCEDURE CSFWindow.DoCancel;
- { Close the window }
- { Override this method to cancel your operations }
-
- BEGIN
-
- Close;
-
- END;
-
-
- PROCEDURE CSFWindow.DoStatus;
- { Bring buttons upto date }
-
- VAR
- Err: OSErr;
- VRefNum: Integer;
-
- BEGIN
-
- { more than one volume mounted }
- IF CountDrives > 1 THEN
- fDrive.Activate
- ELSE
- fDrive.Deactivate;
-
- { Ejectable disks in place }
- IF CheckDrives THEN
- BEGIN
- IF (GetVRefNum(fCurrentWD) = fDrive1) OR (GetVRefNum(fCurrentWD) = fDrive2) THEN
- fEject.Activate
- ELSE
- fEject.Deactivate;
- END
- ELSE
- BEGIN
- fEject.Deactivate;
- END;
-
- fVolumeBox.Refresh;
-
- END;
-
-
- PROCEDURE CSFWindow.DoClick (hitPt: Point; modifierKeys: integer; when: longint);
- Override;
- { Handle clicks in the file box and the puldown menu }
-
- VAR
- b: Boolean;
- TheCell: Cell;
- TheLength: Integer;
- TheDirectory, TheName: Str255;
- TheRect: Rect;
- TheSelection: Str255;
- Temp: Integer;
- Err: OSErr;
-
- BEGIN
-
- { Click in file box? }
- IF PtInRect(hitPt, fViewRect) THEN
- BEGIN
- Prepare;
- ClipRect(MacPort^.PortRect);
- B := LClick(hitPt, modifierKeys, fFileList);
- TheSelection := FindSelection;
- { Inactive }
- IF TheSelection[1] = '-' THEN
- BEGIN
- SetPt(TheCell, 0, 0);
- IF LGetSelect(True, TheCell, fFileList) THEN
- BEGIN
- LSetSelect(False, TheCell, fFileList);
- DoStatus;
- END;
- END
- { Open the file of directory }
- ELSE IF (gClicks > 1) THEN
- BEGIN
- IF TheSelection[1] = '+' THEN
- BEGIN
- IF TheSelection[2] = '@' THEN
- BEGIN
- { Directory }
- fCurrentWD := ChangeDirectory(fCurrentWD, Omit(TheSelection, 1, 2));
- FillDialog(fCurrentWD);
- FindPath(fCurrentWD);
- DoStatus;
- END
- ELSE
- BEGIN
- { File }
- fGood := True;
- fName := Omit(TheSelection, 1, 2);
- Err := GetVol(@fVName, Temp);
- DoCommand(kSelection);
- END;
- END;
- END;
- END;
-
- { Pull down menu }
- IF PtInRect(hitPt, fPathRect) THEN
- BEGIN
- Prepare;
- ClipRect(MacPort^.PortRect);
- LSize(fMenuWidth, fMenuHeight, fPathList);
- fPathRect := fPathList^^.rView;
- InsetRect(fPathRect, -1, -1);
- EraseRect(fPathRect);
- FrameRect(fPathRect);
- DropShadow(fPathRect);
- LUpdate(MacPort^.VisRgn, fPathList);
- B := LClick(hitPt, modifierKeys, fPathList);
-
- LSetSelect(False, ThePathCell, fPathList);
-
- IF ThePathCell.v > 0 THEN
- BEGIN
- { Move up directory tree }
- fCurrentWD := FindParent(fCurrentWD, ThePathCell.v);
- FillDialog(fCurrentWD);
- FindPath(fCurrentWD);
- END
- ELSE
- BEGIN
- SetPathRect;
- END;
- END;
-
- INHERITED DoClick(hitPt, modifierKeys, when);
-
- END;
-
-
- FUNCTION CSFWindow.FileFilter (ParamBlock: CInfoPBPtr): Boolean;
- { Filter out unwanted files from showing in the file box }
-
- BEGIN
-
- { False means to show the file }
- FileFilter := False;
-
- END;
-
-
- FUNCTION CSFWindow.ActiveFilter (ParamBlock: CInfoPBPtr): Boolean;
- { Activate the file--not grayed out }
-
- BEGIN
-
- ActiveFilter := True;
-
- END;
-
-
- PROCEDURE CSFWindow.FillDialog (VRefNum: Integer);
- { Read the directory and fill the file box }
-
- VAR
- Err: OSErr;
- Count, Index: Integer;
- TheTitle: Str255;
- ParamBlock: CInfoPBPtr;
- TheName: Str255;
- TheCell: Cell;
-
- BEGIN
-
- Err := SetVol(NIL, VRefNum);
- ParamBlock := CInfoPBPtr(NewPtr(SizeOf(CInfoPBRec)));
- Index := 1;
- TheCell.h := 0;
- Err := NoErr;
- LDoDraw(False, fFileList);
- LDelRow(0, 0, fFileList);
- WHILE (Err = NoErr) DO
- BEGIN
- TheName := '';
- WITH ParamBlock^ DO
- BEGIN
- ioCompletion := NIL;
- ioNamePtr := @TheName;
- ioVRefNum := VRefNum;
- ioDirID := 0;
- ioDrDirID := 0;
- ioFVersNum := 0;
- ioFDirIndex := Index;
- END;
- Err := PBGetCatInfo(ParamBlock, False);
- IF (Err = fnfErr) THEN
- Leave;
- IF Err <> NoErr THEN
- BEGIN
- { Ka-Boom }
- Index := RedAlert(kSystemError);
- Leave;
- END;
- { Include file or directory? }
- IF FileFilter(ParamBlock) THEN
- BEGIN
- Cycle;
- END;
- { Is it a directory }
- IF IsDirectory(ParamBlock) THEN
- BEGIN
- TheName := Concat('@', TheName);
- END
- ELSE
- BEGIN
- IF ParamBlock^.ioFlFndrInfo.fdType = 'APPL' THEN
- TheName := Concat('#', TheName)
- ELSE
- TheName := Concat('!', TheName);
- END;
- { Grayed? }
- IF ActiveFilter(ParamBlock) THEN
- BEGIN
- { Activate }
- TheName := Concat('+', TheName);
- END
- ELSE
- BEGIN
- { Dectivate }
- TheName := Concat('-', TheName);
- END;
- { Stuff it }
- TheCell.v := LAddRow(1, Maxint, fFileList);
- LSetCell(Ptr(@TheName[1]), Length(TheName), TheCell, fFileList);
- Index := Index + 1;
- END;
- LDoDraw(True, fFileList);
- Prepare;
- ClipRect(GetMacPort^.PortRect);
- EraseRect(fFileList^^.rView);
- LUpdate(MacPort^.VisRgn, fFileList);
- DisposPtr(Ptr(ParamBlock));
-
- END;
-
-
- PROCEDURE CSFWindow.SetPathRect;
- { Find the pull down menu rect }
-
- VAR
- TheString, TheDirectory: Str255;
- TheCell: Cell;
- TheLength: Integer;
- TheRect: Rect;
-
- BEGIN
-
- { Out with the old }
- TheRect := fPathRect;
- InsetRect(TheRect, -1, -1);
- EraseRect(TheRect);
- InvalRect(TheRect);
-
- SetPt(TheCell, 0, 0);
- IF LGetSelect(True, TheCell, fPathList) THEN
- ;
- TheDirectory := GetCellContents(TheCell, fPathList);
- TheLength := StringWidth(TheDirectory) + 28;
- LSize(TheLength, fPathList^^.CellSize.v, fPathList);
- fPathList^^.rView.Left := (((fViewRect.Right - fViewRect.Left + 16) DIV 2) + fViewRect.Left) - (TheLength DIV 2);
- fPathList^^.rView.Right := fPathList^^.rView.Left + TheLength;
- fPathRect := fPathList^^.rView;
-
- SetPt(TheCell, 0, 0);
- TheString := GetCellContents(TheCell, fPathList);
- TheString := Omit(TheString, 1, 2);
- TheLength := StringWidth(TheString);
-
- fPathRect := fPathList^^.rView;
- fPathRect.Right := fPathRect.Left + TheLength + 28;
- InsetRect(fPathRect, -1, -1);
-
- { In with the new }
- InvalRect(TheRect);
- TheRect := fPathRect;
- InsetRect(TheRect, -1, -1);
- InvalRect(TheRect);
- EraseRect(TheRect);
- Update;
-
- END;
-
-
- PROCEDURE CSFWindow.FindPath (VRefNum: Integer);
- { Fill the pull down menu }
-
- VAR
- ParamBlock: CInfoPBPtr;
- TheName, LastName: Str255;
- Err: OSErr;
- TheCell: Cell;
- TheWidth, PathWidth, Ignore: Integer;
- FirstWidth: Boolean;
-
- BEGIN
-
- IF VRefNum = 0 THEN
- Err := GetVol(NIL, VRefNum);
-
- Err := SetVol(NIL, VRefNum);
-
- LastName := '';
- FirstWidth := True;
-
- fMenuWidth := 0;
- fMenuHeight := 0;
-
- { Clear the List }
- LDoDraw(False, fPathList);
- LDelRow(0, 0, fPathList);
-
- ParamBlock := CInfoPBPtr(NewPtr(SizeOf(CInfoPBRec)));
-
- WITH ParamBlock^ DO
- BEGIN
- ioCompletion := NIL;
- ioNamePtr := NIL;
- ioVRefNum := VRefNum;
- ioDirID := 0;
- ioFVersNum := 0;
- ioFDirIndex := 0;
- END;
- Err := PBGetCatInfo(ParamBlock, False);
-
- Err := NoErr;
- WHILE Err = NoErr DO
- BEGIN
- TheName := '';
- WITH ParamBlock^ DO
- BEGIN
- ioCompletion := NIL;
- ioNamePtr := @TheName;
- ioVRefNum := VRefNum;
- ioDirID := 0;
- ioDrDirID := ioDrParID; { We want the parent directory name }
- ioFVersNum := 0;
- ioFDirIndex := -1; { Causes it to give information on ioDrDirID }
- END;
- Err := PBGetCatInfo(ParamBlock, False);
- IF Err = NoErr THEN
- BEGIN
- { Determine a length and compare it, if it is larger then store the value }
- TheWidth := StringWidth(TheName) + 28;
- IF FirstWidth THEN
- BEGIN
- FirstWidth := False;
- PathWidth := TheWidth;
- END;
-
- IF TheWidth > fMenuWidth THEN
- fMenuWidth := TheWidth;
-
- LastName := TheName;
-
- { Add a new row to the list }
- TheName := Concat('+$', TheName);
- TheCell.h := 0;
- TheCell.v := LAddRow(1, Maxint, fPathList);
- LSetCell(Ptr(@TheName[1]), Length(TheName), TheCell, fPathList);
-
- { Increment the height }
- fMenuHeight := fMenuHeight + 16;
- END
- ELSE
- BEGIN
- { Change the icon of the last item }
- IF LastName <> '' THEN
- BEGIN
- Ignore := GetVol(NIL, VRefNum);
- IF CheckDrives THEN
- BEGIN
- IF (fDrive1 = GetVRefNum(VRefNum)) OR (fDrive2 = GetVRefNum(VRefNum)) THEN
- TheName := Concat('+^', LastName)
- ELSE
- TheName := Concat('+%', LastName);
- END
- ELSE
- TheName := Concat('+%', LastName);
- LSetCell(Ptr(@TheName[1]), Length(TheName), TheCell, fPathList);
- END
- ELSE
- sysbeep(1);
- END;
- END;
-
- IF fMenuHeight >= (MacPort^.PortRect.Bottom - fPathRect.Top - 10) THEN
- fMenuHeight := ((MacPort^.PortRect.Bottom - fPathRect.Top - 10) DIV 16) * 16;
-
- InsetRect(fPathRect, -1, -1);
- EraseRect(fPathRect);
- LSize(fMenuWidth, 16, fPathList);
- LDoDraw(True, fPathList);
- SetPathRect;
- FrameRect(fPathRect);
- DropShadow(fPathRect);
-
- DisposPtr(Ptr(ParamBlock));
-
- END;
-
-
- FUNCTION CSFWindow.FindSelection: Str255;
- { Find the first selected item in the file box }
-
- VAR
- TheCell: Cell;
-
- BEGIN
-
- SetPt(TheCell, 0, 0);
- IF LGetSelect(True, TheCell, fFileList) THEN
- FindSelection := GetCellContents(TheCell, fFileList)
- ELSE
- FindSelection := '';
-
- END;
-
-
- PROCEDURE CSFWindow.DoSelection;
- { Set up the SFReply }
-
- VAR
- TheReply: SFReply;
- FndrInfo: FInfo;
- Err: OSErr;
-
- BEGIN
-
- { Set up the reply }
- WITH TheReply DO
- BEGIN
- Good := fGood;
- Copy := False;
- Err := GetFInfo(Self.fName, fCurrentWD, FndrInfo);
- fType := FndrInfo.fdType;
- vRefNum := fCurrentWD;
- Version := 0;
- fName := Self.fName;
- END;
-
- FileSelected(TheReply);
-
- END;
-
-
- PROCEDURE CSFWindow.FileSelected (TheReply: SFReply);
- { Override me!!!!!!!!! This where you handle the reply. }
-
- BEGIN
-
- Sysbeep(1);
-
- END;
-
-
- FUNCTION CSFWindow.RedAlert (AlertID: Integer): Integer;
- { Display error alerts }
-
- CONST
- kAlertOffset = 15;
-
- TYPE
- AlertTHndl = ^AlertTPtr;
- AlertTPtr = ^AlertTemplate;
-
- VAR
- TheAlert: AlertTHndl;
- TheAlertRect, TheRect, TheBounds, TheFrame: Rect;
- ThePoint: Point;
-
- BEGIN
-
- { Get the alert }
- TheAlert := AlertTHndl(GetResource('ALRT', AlertID));
- HNoPurge(Handle(TheAlert));
-
- { Move the alert }
- TheAlertRect := TheAlert^^.boundsRect;
- gDeskTop.GetBounds(TheBounds);
- TheFrame := MacPort^.PortRect;
- LocalToGlobal(TheFrame.TopLeft);
- LocalToGlobal(TheFrame.BotRight);
- IF SectRect(TheBounds, TheFrame, TheRect) THEN
- BEGIN
- ThePoint.v := TheRect.Bottom - TheAlertRect.Bottom - kAlertOffset;
- ThePoint.h := TheRect.Left + kAlertOffset;
- IF NOT PtInRect(ThePoint, TheBounds) THEN
- BEGIN
- IF ThePoint.v < TheBounds.Left THEN
- ThePoint.v := TheBounds.Left;
- IF ThePoint.h < TheBounds.Top THEN
- ThePoint.h := TheBounds.Top;
- END;
- SetRect(TheAlertRect, ThePoint.h, ThePoint.v, ThePoint.h + TheAlert^^.boundsRect.Right, ThePoint.v + TheAlert^^.boundsRect.Bottom);
- IF TheAlertRect.Right > TheBounds.Right THEN
- BEGIN
- TheAlertRect.Left := TheAlertRect.Left - (TheAlertRect.Right - TheBounds.Right);
- TheAlertRect.Right := TheAlertRect.Left + (TheAlertRect.Right - TheBounds.Right);
- END;
- IF TheAlertRect.Bottom > TheBounds.Bottom THEN
- BEGIN
- TheAlertRect.Top := TheAlertRect.Top - (TheAlertRect.Bottom - TheBounds.Bottom);
- TheAlertRect.Bottom := TheAlertRect.Top + (TheAlertRect.Bottom - TheBounds.Bottom);
- END;
- END
- ELSE
- BEGIN
- SetRect(TheAlertRect, TheAlertRect.Left + 100, TheAlertRect.Top + 100, TheAlertRect.Right + 100, TheAlertRect.Bottom + 100);
- END;
-
- { Display the alert }
- TheAlert^^.boundsRect := TheAlertRect;
- RedAlert := Alert(AlertID, NIL);
- HPurge(Handle(TheAlert));
- ReleaseResource(Handle(TheAlert));
-
- END;
-
-
- PROCEDURE CSFGetWindow.MoreInitializations;
- Override;
- { Follow this example to do your initializations }
-
- VAR
- TheSize: Rect;
-
- BEGIN
-
- fEject.Offset(kGetButtonOffset, 76, True);
- fDrive.Offset(kGetButtonOffset, 101, True);
- fCancel.Offset(kGetButtonOffset, 171, True);
-
- SetRect(TheSize, 0, 0, 70, kButtonHeight);
-
- New(fOpen);
- fOpen.IButton(KPushButton, Self, Self);
- fOpen.SetClickCmd(kOpenButton);
- fOpen.ChangeSize(TheSize, False);
- fOpen.Offset(kGetButtonOffset, 146, False);
- fOpen.SetTitle('Open');
- fOpen.Deactivate;
- fOpen.Show;
-
- ChangeSize(363, 215);
-
- END;
-
-
- PROCEDURE CSFGetWindow.DoKeyDown (theChar: char; keyCode: Byte; macEvent: EventRecord);
- Override;
- { Special key handling }
-
- BEGIN
-
- CASE keyCode OF
- $24, $34:
- DoCommand(kOpenButton);
- OTHERWISE
- INHERITED DoKeyDown(theChar, keyCode, macEvent);
- END;
-
- END;
-
-
- PROCEDURE CSFGetWindow.SetfViewRect;
- Override;
- { Resize the file box }
-
- BEGIN
-
- SetRect(fViewRect, 20, 47, 237 - kScrollBarWidth, 47 + (9 * 16));
-
- END;
-
-
- PROCEDURE CSFGetWindow.DoCommand (TheCommand: Longint);
- Override;
- { Do the commands for this subclass }
-
- BEGIN
-
- CASE TheCommand OF
- kOpenButton:
- DoOpen;
- kSelection:
- DoSelection;
- OTHERWISE
- INHERITED DoCommand(TheCommand);
- END;
-
- END;
-
-
- PROCEDURE CSFGetWindow.MoreUpdates;
- Override;
- { Add our updates }
-
- BEGIN
-
- INHERITED MoreUpdates;
-
- PenPat(Gray);
- Moveto(260, 132);
- Lineto(338, 132);
- PenNormal;
-
- END;
-
-
- PROCEDURE CSFGetWindow.DoStatus;
- Override;
- { Add the open button to the status logic }
-
- VAR
- TheCell: Cell;
-
- BEGIN
-
- INHERITED DoStatus;
-
- SetPt(TheCell, 0, 0);
- IF LGetSelect(True, TheCell, fFileList) THEN
- BEGIN
- fOpen.Activate;
- END
- ELSE
- BEGIN
- fOpen.Deactivate;
- END;
-
- END;
-
-
- PROCEDURE CSFGetWindow.DoClick (hitPt: Point; modifierKeys: integer; when: longint);
- Override;
- { Make sure we have the correct file selected }
-
- VAR
- TheCell: Cell;
- SaveDirectory: Integer;
-
- BEGIN
-
- SaveDirectory := fCurrentWD;
-
- INHERITED DoClick(hitPt, modifierKeys, when);
-
- IF (SaveDirectory <> fCurrentWD) AND (fFileList^^.dataBounds.Bottom > 0) THEN
- BEGIN
- Prepare;
- ClipRect(MacPort^.PortRect);
- SetPt(TheCell, 0, 0);
- LSetSelect(True, TheCell, fFileList);
- END;
-
- SetPt(TheCell, 0, 0);
- IF LGetSelect(True, TheCell, fFileList) THEN
- BEGIN
- fOpen.Activate;
- END
- ELSE
- BEGIN
- fOpen.Deactivate;
- END;
-
- END;
-
-
- PROCEDURE CSFGetWindow.Free;
- Override;
- { Get rid of the open button }
-
- BEGIN
-
- fOpen.Free;
-
- INHERITED Free;
-
- END;
-
-
- PROCEDURE CSFGetWindow.DoOpen;
- { Respond to the open button }
-
- VAR
- TheRect: Rect;
- TheSelection: Str255;
- TheCell: Cell;
- Temp: Integer;
- Err: OSErr;
-
- BEGIN
-
- IF fOpen.IsActive THEN
- BEGIN
- TheSelection := FindSelection;
- IF TheSelection[1] = '+' THEN
- BEGIN
- IF TheSelection[2] = '@' THEN
- BEGIN
- { Directory selected }
- fCurrentWD := ChangeDirectory(fCurrentWD, Omit(TheSelection, 1, 2));
- FillDialog(fCurrentWD);
- FindPath(fCurrentWD);
- TheRect := fPathRect;
- InsetRect(TheRect, -1, -1);
- InvalRect(TheRect);
- EraseRect(TheRect);
- Update;
- DoStatus;
-
- Prepare;
- ClipRect(MacPort^.PortRect);
- SetPt(TheCell, 0, 0);
- LSetSelect(True, TheCell, fFileList);
- IF LGetSelect(True, TheCell, fFileList) THEN
- fOpen.Activate;
- END
- ELSE
- BEGIN
- { File selected }
- fGood := True;
- fName := Omit(TheSelection, 1, 2);
- Err := GetVol(@fVName, Temp);
- DoCommand(kSelection);
- END;
- END;
- END;
-
- END;
-
-
- PROCEDURE CSFSaveWindow.MoreInitializations;
- Override;
- { Move existing buttons and add the save button and edit box }
-
- VAR
- TheSize: Rect;
-
- BEGIN
-
- fEject.Offset(kSaveButtonOffset, 64, True);
- fDrive.Offset(kSaveButtonOffset, 90, True);
- fCancel.Offset(kSaveButtonOffset, 166, True);
-
- SetRect(TheSize, 0, 0, 70, kButtonHeight);
-
- New(fSave);
- fSave.IButton(KPushButton, Self, Self);
- fSave.SetClickCmd(kSaveButton);
- fSave.ChangeSize(TheSize, False);
- fSave.Offset(kSaveButtonOffset, 140, False);
- fSave.SetTitle('Save');
- fSave.Deactivate;
- fSave.Show;
-
- fPromptString := 'Save file as…';
-
- New(fFileName);
- fFileName.IEditText(Self, Self, fViewRect.Right - fViewRect.Left - 4, 16, fViewRect.Left + 2, fViewRect.Bottom + 30, sizFIXEDLEFT, sizFIXEDTOP, -1);
- fFileName.SelectText;
- fFileName.Show;
-
- ChangeSize(319, 199);
- SetTitle('Save');
-
-
- END;
-
-
- PROCEDURE CSFSaveWindow.SetfViewRect;
- Override;
- { Move the file box }
-
- BEGIN
-
- SetRect(fViewRect, 22, 37, 204 - kScrollBarWidth, 37 + (6 * 16));
-
- END;
-
-
- FUNCTION CSFSaveWindow.ActiveFilter (ParamBlock: CInfoPBPtr): Boolean;
- Override;
- { Only activate directories }
-
- BEGIN
-
- IF ParamBlock^.ioFlFndrInfo.fdType = 'APPL' THEN
- BEGIN
- ActiveFilter := False;
- Exit(ActiveFilter);
- END;
-
- IF IsDirectory(ParamBlock) THEN
- ActiveFilter := True
- ELSE
- ActiveFilter := False;
-
- END;
-
-
- PROCEDURE CSFSaveWindow.Activate;
- Override;
- { Set the gopher to the edit box }
-
- BEGIN
-
- INHERITED Activate;
- gGopher := fFileName;
-
- END;
-
-
- PROCEDURE CSFSaveWindow.DoCommand (TheCommand: Longint);
- Override;
- { Handle the commands for this subclass }
-
- BEGIN
-
- CASE TheCommand OF
- kSaveButton:
- DoSave;
- kSelection:
- DoSelection;
- kEmptyText:
- fSave.Deactivate;
- kNonEmptyText:
- fSave.Activate;
- OTHERWISE
- INHERITED DoCommand(TheCommand);
- END;
-
- END;
-
-
- PROCEDURE CSFSaveWindow.MoreUpdates;
- Override;
- { Update edit box }
-
- VAR
- TheRect: Rect;
-
- BEGIN
-
- INHERITED MoreUpdates;
-
- IF IsVisible THEN
- BEGIN
- TheRect := fFileName.Frame;
- fFileName.FrameToEnclR(TheRect);
- InSetRect(TheRect, -3, -3);
- FrameRect(TheRect);
- END;
-
- Moveto(fViewRect.Left, fViewRect.Bottom + 21);
- DrawString(fPromptString);
-
- END;
-
-
- PROCEDURE CSFSaveWindow.Free;
- Override;
- { Dispose of the save button and edit box }
-
- BEGIN
-
- fSave.Free;
- fFileName.Free;
-
- INHERITED Free;
-
- END;
-
-
- FUNCTION CSFSaveWindow.FileExists (vRefNum: Integer; TheName: Str255): Boolean;
- { Find out if the file is already on the disk }
-
- VAR
- FndrInfo: FInfo;
- Err: OSErr;
- Ignore: Integer;
- ParamBlock: CInfoPBRec;
-
- BEGIN
-
- Prepare;
- WITH ParamBlock DO
- BEGIN
- ioCompletion := NIL;
- ioNamePtr := @TheName;
- ioVRefNum := VRefNum;
- ioDrDirID := 0;
- ioDirID := 0;
- ioFVersNum := 0;
- ioFDirIndex := 0;
- END;
- Err := PBGetCatInfo(@ParamBlock, False);
- IF IsDirectory(@ParamBlock) THEN
- BEGIN
- Err := NoErr;
- END;
-
- CASE Err OF
- fnfErr:
- BEGIN
- FileExists := False;
- END;
- NoErr:
- BEGIN
- CASE Rename(TheName, vRefNum, TheName) OF
- fLckdErr, vLckdErr, wPrErr:
- BEGIN
- Ignore := RedAlert(kLockedDisk);
- FileExists := True;
- Exit(FileExists);
- END;
- END;
- ParamText(TheName, '', '', '');
- IF RedAlert(kExistingFile) = 1 THEN
- FileExists := True
- ELSE
- FileExists := False;
- END;
- OTHERWISE
- BEGIN
- Ignore := RedAlert(kSystemError);
- FileExists := True;
- END;
- END;
-
- END;
-
-
- PROCEDURE CSFSaveWindow.DoSave;
- { Respond to the save button }
-
- VAR
- Temp: Integer;
- Err: OSErr;
-
- BEGIN
-
- IF fSave.IsActive THEN
- BEGIN
- fGood := True;
- fName := fFileName.GetStr255;
- Err := GetVol(@fVName, Temp);
- IF NOT FileExists(Temp, fName) THEN
- BEGIN
- DoCommand(kSelection);
- FillDialog(fCurrentWD);
- END;
- END;
-
- END;
-
-
-
- PROCEDURE CSFDialog.ICSFDialog;
- { Initialize and install our window subclass }
-
- BEGIN
-
- IDirector(gApplication);
- New(CSFWindow(ItsWindow));
- CSFWindow(ItsWindow).ICSFWindow(Self);
-
- FKeyEnable(False);
-
- END;
-
-
- PROCEDURE CSFGetDialog.ICSFDialog;
- Override;
- { Initialize and install our window subclass }
-
- BEGIN
-
- IDirector(gApplication);
- New(CSFGetWindow(ItsWindow));
- CSFGetWindow(ItsWindow).ICSFWindow(Self);
-
- FKeyEnable(False);
-
- END;
-
-
- PROCEDURE CSFSaveDialog.ICSFDialog;
- Override;
- { Initialize and install our window subclass }
-
- BEGIN
-
- IDirector(gApplication);
- New(CSFSaveWindow(ItsWindow));
- CSFSaveWindow(ItsWindow).ICSFWindow(Self);
-
- itsGopher := CSFSaveWindow(ItsWindow).fFileName;
-
- FKeyEnable(False);
-
-
- END;
-
-
- PROCEDURE CSFSwitchboard.DoDiskEvent (macEvent: EventRecord);
- Override;
- { Intercept disk events }
-
- BEGIN
-
- INHERITED DoDiskEvent(macEvent);
- gGopher.DoCommand(cmdDiskEvent);
-
- END;
-
-
- PROCEDURE CSFApplication.ICSFApplication (extraMasters: integer; aRainyDayFund, aCreditLimit: Size);
- { Install the new switchboard }
-
- CONST
- JUMPBUFFER_A1 = 5; { Index of A1 in JumpBuffer }
-
- BEGIN
-
- MenuDisable := LongPtr($B54); { Low-memory global }
-
- nullStr := '';
-
- { We haven't reached the event loop yet. }
- { Flag A1 (jump addr) so we don't try to jump there. }
-
- eventLoopJump[JUMPBUFFER_A1] := 0;
-
- InitToolbox;
-
- InitMemory(extraMasters, aRainyDayFund, aCreditLimit);
-
- { Instance Variables }
-
- IBureaucrat(NIL);
-
- { Install CSF switchboard }
- new(CSFSwitchboard(itsSwitchboard));
- itsSwitchboard.ISwitchboard;
-
- new(itsDirectors);
- itsDirectors.ICluster;
- new(itsIdleChores);
- itsIdleChores.IList;
- new(itsUrgentChores);
- itsUrgentChores.ICluster;
- urgentsToDo := FALSE;
- running := TRUE;
-
- { Global Variables }
-
- gSignature := '????';
- gHasWNE := WNEIsImplemented;
- gSleepTime := 0; { We want an early first Idle }
- new(gError);
-
- { Cursors }
-
- gIBeamCursor := GetCursor(iBeamCursor);
- HNoPurge(Handle(gIBeamCursor));
- gWatchCursor := GetCursor(watchCursor);
- HNoPurge(Handle(gWatchCursor));
-
- gUtilRgn := NewRgn;
-
- MakeDesktop;
- MakeClipboard;
- MakeDecorator;
- SetUpFileParameters;
- SetUpMenus;
-
- gGopher := SELF;
- gLastViewHit := NIL;
- gLastMouseUp.when := 0;
- gClicks := 0;
-
- END;
-
- END.